﻿using System.Diagnostics.CodeAnalysis;
using OrderMicroService.Types.Types;

namespace OrderMicroService.Domain.Repository
{
    public interface IRepository<TAggregate, TIdentifier>
        where TAggregate : IAggregate<TIdentifier>
        where TIdentifier : IIdentifier
    {
        /// <summary>
        /// 将一个 Aggregate 附属到一个 Repository，让它变为可追踪。
        /// </summary>
        /// <param name="aggregate"></param>
        void Attach([NotNull] TAggregate aggregate);

        /// <summary>
        /// 解除一个 Aggregate 的追踪
        /// </summary>
        /// <param name="T"></param>
        /// <param name=""></param>
        void Detach([NotNull] TAggregate aggregate);

        /// <summary>
        /// 通过 ID 寻找 Aggregate。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TAggregate Find([NotNull] TIdentifier id);

        /// <summary>
        /// 将一个 Aggregate 从 Repository 移除, 操作后的 aggregate 对象自动取消追踪
        /// </summary>
        /// <param name="aggregate"></param>
        void Remove([NotNull] TAggregate aggregate);

        /// <summary>
        /// 保存一个 Aggregate,保存后自动重置追踪条件
        /// </summary>
        /// <param name="aggregate"></param>
        void Save([NotNull] TAggregate aggregate);
    }
}